import dataType from './dataType'

export default {
  name: 'FormatterComponent',
  functional: true,
  props: {
    row: Object,
    options: Object,
    index: Number,
    column: String,
    format: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      formatter: dataType
    }
  },
  render: (h, ctx) => {
    const { format, column, row, options } = ctx.props
    var _opts = options || {}
    if (format.options) {
      // _opts = _opts ? { ..._opts, ...format.options } : format.options
      _opts = Object.assign({}, options, format.options)
    }
    return h(
      dataType[format.type] || dataType.text,
      {
        props: {
          value: row[column],
          row: row,
          options: _opts
        }
      },
      ctx.children
    )
  }
}
